//
//  KKArticalCell.m
//  DoMi
//
//  Created by 康凯 on 2016/11/23.
//  Copyright © 2016年 kk. All rights reserved.
//

#import "KKArticalCell.h"
#import "KKArticleContentM.h"

@implementation KKArticalCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
-(void)initData:(KKArticleListM *)data{
    [self.avatar sd_setImageWithURL:[NSURL URLWithString:data.avatar] placeholderImage:[UIImage imageNamed:@"default_avater"]];
    self.name.text=data.nickname;
    self.title.text=data.title;
    self.time.text=data.systime;
    float width=[KKAppUtils sizeWithText:data.job font:[UIFont systemFontOfSize:12] maxSize:CGSizeMake(100, 14)].width;
    self.jobWidth.constant=width+5;
    self.job.text=data.job;
    self.label.text=data.label;
    self.replyCount.text=data.commentcount;
    self.likeCount.text=data.doclikecount;
    //内容
    if(data.content!=nil&&data.content.count>0){
        NSDictionary *dic= data.content[0];
        self.content.text=dic[@"content"];
    }else{
        self.content.text=@"无内容";
    }
//    self.content.text=data.content[0];
    //图片
    for (UIView *subView in self.contentImg.subviews) {
        [subView removeFromSuperview];
    }
    if(data.contentimg!=nil&&data.contentimg.count>0){
        self.imgHeight.constant=50;
        self.containerHeight.constant=150;
        CGFloat perWidth=(screenWidth-45-20)/5;
        for(int i=0;i<data.contentimg.count;i++){
            KKArticleContentM *content= data.contentimg[i];
            CGFloat tempWidth;
            if(i!=0){
                tempWidth=perWidth+5;
            }else{
                tempWidth=perWidth;
            }
            UIImageView *userImg=[[UIImageView alloc] initWithFrame:CGRectMake(i*tempWidth,0, perWidth-10, 50)];
            [userImg sd_setImageWithURL:[NSURL URLWithString:content.content]];
            [self.contentImg addSubview:userImg];
        }
    }else{
        self.imgHeight.constant=0;
        self.containerHeight.constant=100;
    }
}

-(void)initRankData:(KKStudyList *)data{
    [self.avatar sd_setImageWithURL:[NSURL URLWithString:data.avatar] placeholderImage:[UIImage imageNamed:@"default_avater"]];
    self.name.text=data.nickname;
    self.title.text=data.title;
    self.label.text=data.lable;
    self.content.text=data.content;
    self.replyCount.text=data.commentcoun;
    self.likeCount.text=data.doclikecoun;
    
}
@end
